<template>
  <el-button @click="refresh()">refresh</el-button>
  <el-button @click="settle()">settle</el-button>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column type="index" label="index" width="180" />
    <el-table-column prop="title" label="商品名" width="180" />
    <el-table-column prop="price" label="单价" />
    <el-table-column prop="num" label="数量" />
    <el-table-column label="Operations">
      <!-- scope is row data -->
      <template #default="scope"> 
        <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
          >Edit</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
import { inject } from 'vue';
import { useRouter } from 'vue-router'
import { ref } from 'vue'
import { fetch_x } from '/src/api/fetch_wrapper.js'

const server_host = inject('h');
const router = useRouter();

const tableData = ref([]);

async function refresh() {
  try {
    const s = await fetch_x(server_host + "/f1/cart/user/list", {
      method: "post",
      headers: {
        "Content-Type": "application/json"
      },
    });
    tableData.value = s;

  } catch (e) {
    console.log(e);
  }
}
refresh();

async function settle() {
    const res = await fetch_x(server_host + "/sg-oss/trade/settle", {
      method: "post",
      headers: {
        "Content-Type": "application/json",
      },
    });
  refresh();
}

</script>
<style>
.demo-tabs>.el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
</style>
  